import Mock from "mockjs";
import { MockMethod } from "vite-plugin-mock";
import utils from "../../../src/utils/utils";
import contextPath from "../../context-path";
const Random = Mock.Random;

export default [
  {
    url: contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/code.listing",
    method: "post",
    response: (options) => {
      const rows: any[] = [];
      const total = 112;
      let cnt = options.body.rows;
      if (options.body.rows * options.body.page > total) {
        cnt = total - options.body.rows * (options.body.page - 1);
      }
      for (let i = 0; i < cnt; i++) {
        const template = {
          codeId: Random.guid(),
          parentId: Random.guid(),
          levelCode: Random.natural(60, 1000),
          name: Random.cparagraph(1),
          code: Random.string("upper", 5),
          value: Random.natural(60, 1000),
          extension0: Random.cname(),
          extension1: Random.cname(),
          visibled: Mock.mock({
            "array|1": [0, 1],
          }).array,
          description: Random.cparagraph(2),
        };
        rows.push(template);
      }

      return {
        code: 200,
        total: total,
        rows: rows,
      };
    },
  },
  {
    url: contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/code.get",
    method: "post",
    response: (options) => {
      const template = {
        codeId: Random.guid(),
        parentId: Random.guid(),
        levelCode: Random.natural(60, 1000),
        name: Random.cparagraph(1),
        code: Random.string("upper", 5),
        value: Random.natural(60, 1000),
        path: ["sys-root", "email", "email-send"],
        extension0: Random.cname(),
        extension1: Random.cname(),
        visibled: Mock.mock({
          "array|1": [0, 1],
        }).array,

        description: Random.cparagraph(2),
      };

      return {
        code: 200,
        message: "",
        data: template,
      };
    },
  },

  {
    url: contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/code.update",
    method: "post",
    response: (options) => {
      return {
        code: 200,
        message: "",
        data: null,
      };
    },
  },
  {
    url: contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/code.delete",
    method: "post",
    response: (options) => {
      return {
        code: 200,
        message: "",
        data: null,
      };
    },
  },
  {
    url:
      contextPath.VITE_API_ADMIN_CONTEXT_PATH +
      "/admin/api/code.visible.change",
    method: "post",
    response: (options) => {
      return {
        code: 200,
        message: "",
        data: null,
      };
    },
  },

  {
    url:
      contextPath.VITE_API_ADMIN_CONTEXT_PATH +
      "/admin/api/code.children.listing",
    method: "post",
    response: (options) => {
      // console.log("queryCodeChildrenListing");

      const nodes: any[] = [];

      let parentId = options.body.parentId;
      if (parentId == "0") {
        let node = {
          codeId: "sys-root",
          parentId: parentId,
          name: "系统",
          code: "SYS",
          value: "",
          leaf: false,
          children: [],
        };
        nodes.push(node);
      }
      if (parentId == "sys-root") {
        let node = {
          codeId: "email",
          parentId: "root-root",
          name: "邮件参数",
          code: "SYS_EMAIL",
          value: "",
          leaf: false,
          children: [],
        };
        nodes.push(node);
      }
      if (parentId == "email") {
        let node = {
          codeId: "email-send",
          parentId: "email",
          name: "邮件发送人",
          code: "SYS_EMAIL_SEND",
          value: "abc@abc.com",
          leaf: true,
          children: [],
        };
        nodes.push(node);
      }
      if (parentId == "email") {
        let node = {
          codeId: "email-smtp",
          parentId: "email",
          name: "邮件发服务器地址",
          code: "SYS_EMAIL_SMTP",
          value: "smtp@abc.com",
          leaf: true,
          children: [],
        };
        nodes.push(node);
      }

      if (parentId == "0") {
        let node = {
          codeId: "app-root",
          parentId: parentId,
          name: "应用",
          code: "APP",
          value: "",
          leaf: false,
          children: [],
        };
        nodes.push(node);
      }
      if (parentId == "app-root") {
        let node = {
          codeId: "xueli",
          parentId: "app-root",
          name: "学历类型",
          code: "APP_XUELI",
          value: "",
          leaf: true,
          children: [],
        };
        nodes.push(node);
      }
      if (parentId == "app-root") {
        let node = {
          codeId: "airport",
          parentId: "app-root",
          name: "机场信息",
          code: "SYS_AIRPORT",
          value: "",
          leaf: true,
          children: [],
        };
        nodes.push(node);
      }

      return {
        code: 200,
        message: "",
        data: nodes,
      };
    },
  },
] as MockMethod[];
